home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / phires.exe / 640X400.C < prev    next >
C/C++ Source or Header  |  1993-03-23  |  5KB  |  168 lines

  1. /*
  2.  * Info for setting video mode 640x400 gleaned from Ralf Brown's invaluable
  3.  * Interrupt List.
  4.  *
  5.  * Other port-setting stuff is by Ben Morris.
  6.  *
  7.  * This mode uses planar writes.  If you don't know what these are,
  8.  * it's really simple:
  9.  *
  10.  *   Planar mode was devised to get around the losers who decided
  11.  *   that memory should be accessed in 64k segments.  Most planar
  12.  *   video modes use 4 horizontal planes, thus dividing the actual
  13.  *   amount of video memory displayed by 4.  Basically, all 256000
  14.  *   bytes of video memory (which is what's used in 640x400) is
  15.  *   accessible in 64000 bytes.
  16.  *
  17.  *   The thing about planar mode is that you have
  18.  *   to tell the video card (CRTC) to turn on the desired planes when
  19.  *   you want to write.  Since there are four planes, and you can
  20.  *   set any combination of the four (like 0-2-3, 1-3, 0-1-2-3),
  21.  *   the CRTC requires that you pass it a byte explaining which
  22.  *   bits to set.
  23.  *
  24.  *   This is really GOOD for lots of repetitive stuff (like filling
  25.  *   polygons with one color, etc), because it allows you to write
  26.  *   up to four bytes at a time.
  27.  *
  28.  *   The BAD thing about this comes when looking at bitmaps.  Bitmaps
  29.  *   are usually quite random.  Basically, you'll have to set the
  30.  *   appropriate plane EACH AND EVERY TIME you want to write a pixel.
  31.  *
  32.  *   I included a really simple pixel routine so you can see exactly
  33.  *   what my really bad explanation skills are trying to say. :).
  34.  *
  35.  * <grin>.
  36.  *
  37.  * PS:  This code works with the ATI card.  If you have a different
  38.  * card (like a TSENG 4000 chipset), re-#define VIDMODE (below) to
  39.  * the right card.
  40.  *
  41.  */
  42. #include    <dos.h>
  43. #include    <conio.h>
  44. #include    <stdio.h>
  45. #include    <mem.h>
  46.  
  47. #define     ATI_VGA         0x61
  48. #define     TECMAR_VGA_AD   0x1B
  49. #define     TSENG_4000      0x2F
  50. #define     LOGIX           0x5C
  51. #define     ATI_PRISM       0x5C
  52. #define     MAXXON          0x5C
  53. #define     SEFCO_TVGA      0x5C
  54. #define     IMTEC           0x5C
  55. #define     ZYMOS_POACH     0x5C
  56. #define     TRIDENT_8800    0x5C
  57. #define     TRIDENT_8900    0x5C
  58. #define     PARADISE_VGA    0x5E
  59. #define     VEGA_VGA        0x5E
  60. #define     AST_VGA_PLUS    0x5E
  61. #define     COMPAQ_VGA      0x5E
  62. #define     AT_T_VDC600     0x5E
  63. #define     TATUNG_VGA      0x66
  64. #define     STB_VGA_EM16    0x78
  65. #define     CARDINAL        0x78
  66.  
  67. #define     VIDMODE         ATI_VGA
  68. #define     UNKNOWN         -1
  69. #define     unint           unsigned int
  70.  
  71. /* Only available with 512k of ram */
  72. #define     page1()         outport(0x3D4, 0x800C)
  73. #define     page0()         outport(0x3D4, 0x0C)
  74.  
  75. /*---------------------------------------------------------------------------*/
  76.  
  77. int autodetect( void )
  78. /* This function will attempt to autodetect the video card/chipset in use.
  79.  * I only have a small amount of information about it.
  80.  *
  81.  * Returns UNKNOWN (-1), or one of the #defines from above.
  82.  *
  83.  * If you have any more information about autodetection, PLEASE e-mail me
  84.  * at the above addresses.
  85.  *
  86.  */
  87. {
  88.     char far *ptr;
  89.  
  90.     /* Check for ATI? */
  91.     ptr = (char far *) 0xc0000031L;
  92.     if( !memcmp( ptr, "761295520", 9 ) )
  93.     {
  94.         /* It's an ATI, but what kind? */
  95.         ptr = (char far *) 0xc0000040L;
  96.  
  97.         /* The signature "31" at this address means it's a VGA Wonder or compat. */
  98.         if( !memcmp( ptr, "31", 2 ) )
  99.             return ATI_VGA;
  100.  
  101.         goto unknown;
  102.     }
  103.  
  104.     /* Check for Paradise VGA? */
  105.     ptr = (char far *) 0xc000007d;
  106.     if( !memcmp( ptr, "VGA=", 4 ) )
  107.         return PARADISE_VGA;
  108.  
  109. unknown:
  110.     return UNKNOWN;
  111. }
  112.  
  113. /*---------------------------------------------------------------------------*/
  114.  
  115. void pixel( int page, int x, int y, char color )
  116. /* NOTE: PAGES ARE NOT FUNCTIONAL!  Can anyone tell me why?
  117.  */
  118. {
  119.     char    far *scr = (char far *) (0xa0000000L + (0x40000L * page)) + y * 160 + x / 4;
  120.     unint   masks[] = { 0x0102, 0x0202, 0x0402, 0x0802 };
  121.  
  122.     /* By the way, the masks above are used for plane setting.  EG:
  123.      * masks[0] sets plane 0, and so on.
  124.      */
  125.     outport( 0x3C4, masks[x%4] );
  126.     *scr = color;
  127. }
  128.  
  129. /*---------------------------------------------------------------------------*/
  130.  
  131. void main( void )
  132. {
  133.     long    i, i2;
  134.     char    far *scr = (char far *) 0xa0000000L;
  135.     int     vtype = autodetect();
  136.  
  137.     if( vtype != -1 )
  138.     {
  139.         printf( "Video adaptor: 0x%X\n", vtype );
  140.         getch();
  141.     }
  142.  
  143.     _AH = 0;
  144.     _AL = vtype == -1 ? VIDMODE : vtype;
  145.     asm int 10h;
  146.  
  147.     outport( 0x3C4, 0x0604 );  /* turn off chain 4 + odd/even */
  148.     outport( 0x3CE, 0x0106 );  /* turn off chain */
  149.     outport( 0x3C4, 0x0f02 );  /* enable all planes */
  150.  
  151.     /* This writes 4 pixels at a time. */
  152.     for( i = 0; i < 160L*400L; i++ )
  153.         *scr++ = 15;
  154.  
  155.     getch();
  156.  
  157.     /* To see how slow planar writes are! */
  158.     for( i = 0; i < 400L; i++ )
  159.         for( i2 = 0; i2 < 640L; i2++ )
  160.             pixel( 1, i2, i, 9 );
  161.  
  162.     getch();
  163.  
  164.     _AH = 0;
  165.     _AL = 3;
  166.     asm int 10h;
  167. }
  168.